<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2008
 */


/**
 *
 *
 */
class Selector{
   /**
    * Constructor
    * @access protected
    */
    private $select;
    private $from;
    private $critere;

   function addChamp($champP){
      if( !empty($this->select) )
      {
         $this->select .= ", ";
      }
      $this->select .= $champP;
   }

   function addFrom($tableP){
      if( !empty($this->from) )
      {
         $this->from .= ", ";
      }
      $this->from .= $tableP;
   }

   function addCritere($champP, $critereP){
      $this->addCritereOperateur('=', $champP, $critereP);
   }

   function addCritereLike($champP, $critereP){
      $this->addCritereOperateur('LIKE', $champP, $critereP);
   }

   function addCritereSpecif($critere){
      if( !empty($this->critere) )
      {
         $this->critere .= " AND ";
      }
      $this->critere .= $critere;
   }

    function addCritereOperateur($operateur, $champP, $critereP){
      if( !empty($this->critere) )
      {
         $this->critere .= " AND ";
      }
      $this->critere .= $champP . " " . $operateur . " '" . $critereP . "'";
   }

   /*
   Formate la requete
   */
   function toString() {

      if ($this->critere != "") {
         return 'SELECT ' . $this->select . ' FROM ' . $this->from . ' WHERE ' . $this->critere . ';';
      } else {
         return 'SELECT ' . $this->select . ' FROM ' . $this->from . ';';
      }

   }

}

?>